package com.dao;

import java.util.List;
import com.bean.Announce;
import com.bean.AnnouncePage;
import com.bean.Book;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

/**
 * @ClassName AnnounceDao
 * @Desc 公告数据控制层
 * @Author xiaoding
 * @Date 2021/1/17 21:16
 * @Version 1.0
 */

public class AnnounceDao {

    /*
     * @Author announceSelect
     * @Description 查询所有公告信息
     * @Date 21:19 2021/1/17
     * @Param announcePage
     * @return java.util.List<com.bean.Announce>
     */
    public List<Announce> announceSelect(AnnouncePage announcePage) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.AnnounceMapping.announceSelect";
        List<Announce> list = session.selectList(sql,announcePage);
        return list;
    }

    /*
     * @Author announceSelectId
     * @Description 根据公告Id，查询公告信息
     * @Date 19:49 2021/1/20
     * @Param id
     * @return com.bean.Announce
     */
    public Announce announceSelectId(int id) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.AnnounceMapping.announceSelectId";
        Announce announce = session.selectOne(sql,id);
        return announce;
    }

    /*
     * @Author announceSelects
     * @Description 无分页查询所有公告信息
     * @Date 21:41 2021/1/17
     * @Param
     * @return java.util.List<com.bean.Announce>
     */
    public List<Announce> announceSelects() {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.AnnounceMapping.announceSelects";
        List<Announce> list = session.selectList(sql);
        return list;
    }

    /*
     * @Author announceSearch
     * @Description 根据标题查询公告信息
     * @Date 21:20 2021/1/17
     * @Param announcePage
     * @return java.util.List<com.bean.Announce>
     */
    public List<Announce> announceSearch(AnnouncePage announcePage) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.AnnounceMapping.announceSearch";
        List<Announce> list = session.selectList(sql,announcePage);
        return list;
    }

    /*
     * @Author announceCount
     * @Description 查询所有公告数量
     * @Date 21:22 2021/1/17
     * @Param
     * @return int
     */
    public int announceCount() {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.AnnounceMapping.announceCount";
        int a = session.selectOne(sql);
        return a;
    }

    /*
     * @Author announceSearchCount
     * @Description 根据标题查询所有公告数量
     * @Date 21:22 2021/1/17
     * @Param title
     * @return int
     */
    public int announceSearchCount(String titles) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.AnnounceMapping.announceSearchCount";
        int a = session.selectOne(sql);
        return a;
    }

    /*
     * @Author addAnnounce
     * @Description 添加公告
     * @Date 21:24 2021/1/17
     * @Param announce
     * @return int
     */
    public int addAnnounce(Announce announce) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.AnnounceMapping.addAnnounce";
        int a = session.insert(sql,announce);
        session.commit();
        return a;
    }

    /*
     * @Author updateAnnounce
     * @Description 修改公告信息
     * @Date 21:25 2021/1/17
     * @Param announce
     * @return int
     */
    public int updateAnnounce(Announce announce) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.AnnounceMapping.updateAnnounce";
        int a = session.update(sql,announce);
        session.commit();
        return a;
    }

    /*
     * @Author deleteAnnounce
     * @Description 根据公告Id，删除公告信息
     * @Date 21:27 2021/1/17
     * @Param id
     * @return int
     */
    public int deleteAnnounce(int id) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.AnnounceMapping.deleteAnnounce";
        int a = session.delete(sql,id);
        session.commit();
        return a;
    }
}
